#pragma once
#ifndef GRAPHICSOBJECT_H_
#define GRAPHICSOBJECT_H_

#include "transformobject.h"
#include "texturesdl.h"
#include "textureogl.h"
#include "color.h"

namespace EPOC
{
	class GraphicsUVData
	{
		public:
			GraphicsUVData(float fUStart, float fUEnd, float fVStart, float fVEnd) : m_fUStart(fUStart), m_fUEnd(fUEnd), m_fVStart(fVStart), m_fVEnd(fVEnd)
			{};

			GraphicsUVData() : m_fUStart(0.0f), m_fUEnd(1.0f), m_fVStart(0.0f), m_fVEnd(1.0f)
			{};
		
		public:
			float m_fUStart;
			float m_fUEnd;
			float m_fVStart;
			float m_fVEnd;
	}; // class GraphicsUVData
}; // namespace EPOC

namespace EPOC
{
	const unsigned int BLEND_ZERO = GL_ZERO;
	const unsigned int BLEND_ONE = GL_ONE;
	
	const unsigned int BLEND_SRC_COLOR = GL_SRC_COLOR;
	const unsigned int BLEND_DST_COLOR = GL_DST_COLOR;

	const unsigned int BLEND_ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR;
	const unsigned int BLEND_ONE_MINUS_DST_COLOR = GL_ONE_MINUS_DST_COLOR;
	
	const unsigned int BLEND_SRC_ALPHA = GL_SRC_ALPHA;
	const unsigned int BLEND_DST_ALPHA = GL_DST_ALPHA;

	const unsigned int BLEND_ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA;
	const unsigned int BLEND_ONE_MINUS_DST_ALPHA = GL_ONE_MINUS_DST_ALPHA;

	const unsigned int BLEND_CONSTANT_COLOR = GL_CONSTANT_COLOR;
	const unsigned int BLEND_CONSTANT_ALPHA = GL_CONSTANT_ALPHA;

	const unsigned int BLEND_ONE_MINUS_CONSTANT_COLOR = GL_ONE_MINUS_CONSTANT_COLOR;
	const unsigned int BLEND_ONE_MINUS_CONSTANT_ALPHA = GL_ONE_MINUS_CONSTANT_ALPHA;

	const unsigned int BLEND_SRC_ALPHA_SATURATE = GL_SRC_ALPHA_SATURATE;
};

namespace EPOC
	{
	class GraphicsObject : public TransformObject
	{
	public:
		enum BLENDMODE_PRESET
		{
			kBLENDMODE_PRESET_ADDITIVE,			// ONE_ONE
			kBLENDMODE_PRESET_ALPHAMASK,			// SRCALPHA_MINUSSRCALPHA
			kBLENDMODE_PRESET_CUSTOM
		};

	public:
	//con-/destructors
		GraphicsObject();
		virtual ~GraphicsObject();

	// public methods
		virtual void Cleanup();
		virtual bool Initialize(Texture *pTexture/*, RENDER_MODE nRenderMode*/);
		virtual void Render( );
	    
		virtual ColorRGBA GetPixelColorAt(int nX, int nY);
		virtual void SetPixelColorAt(int nX, int nY, ColorRGBA *pColor);
		virtual bool IsVisibleWindow(int nWindowWidth, int nWindowHeight);
		virtual void SetPresetBlendMode(BLENDMODE_PRESET nBlendMode);

	// public helpers
		inline void SetTexture(Texture *pTexture)			{ m_pTexture = pTexture;}
		inline Texture* GetTexture()						{ return m_pTexture;}
		inline void SetPivotCentered(bool bStatus = true)	{ m_bPivotCentered = bStatus;}
		inline bool IsPivotCentered()						{ return m_bPivotCentered;}
		inline unsigned int GetZOrder()						{ return m_nZOrder;}
		inline void SetZOrder(unsigned int nZOrder)			{ m_nZOrder = nZOrder;}
		inline void SetVisible(bool bStatus)				{ m_bVisible = bStatus;}
		inline bool IsVisible()								{ return m_bVisible;}
		inline void SetCullingEnabled(bool bStatus)			{ m_bCullingEnabled = bStatus;}
		inline bool IsCullingEnabled()						{ return m_bCullingEnabled;}
		inline GraphicsUVData* GetUVData()					{ return &m_rUVdata;}
		//inline RENDER_MODE GetRenderMode()					{ return m_nRenderMode;}

		inline void SetAlphaEnabled(bool bStatus)		{ m_bAlphaEnabled = bStatus;}		
		inline bool IsAlphaEnabled()					{ return m_bAlphaEnabled;}
		inline void SetColorkeyEnabled(bool bStatus)	{ m_bColorKeyEnabled = bStatus;}
		inline bool IsColorkeyEnabled()					{ return m_bColorKeyEnabled;}
		inline void SetAlpha(Uint8 nAlpha = 255)		{ m_nAlpha = nAlpha;}
		inline Uint8 GetAlpha()							{ return m_nAlpha;}
		inline void SetColorKey(ColorRGB rColorKey)		{ m_rColorKey = rColorKey;}
		inline ColorRGB GetColorKey()					{ return m_rColorKey;}
		inline void SetCustomBlendFactors(unsigned int nSrc, unsigned int nDest) { SetPresetBlendMode(kBLENDMODE_PRESET_CUSTOM); m_nBlendFactorSrc = nSrc; m_nBlendFactorDest = nDest;}

		inline void SetAlphaRejection(float fAlphaRef)	
		{ 
			m_fAlphaRef = fAlphaRef;
			
			if(	m_fAlphaRef < 0.0f)
				m_fAlphaRef = 0.0f;
			else if(m_fAlphaRef > 1.0f)
				m_fAlphaRef = 1.0f;
			
		}
		inline float GetAlphaRejection()				{ return m_fAlphaRef;}

	protected:
		virtual ColorRGBA GetPixelColorAtSDL(int nX, int nY);
		virtual void SetPixelColorAtSDL(int nX, int nY, ColorRGBA *pColor);
		virtual ColorRGBA GetPixelColorAtOGL(int nX, int nY);
		virtual void SetPixelColorAtOGL(int nX, int nY, ColorRGBA *pColor);
		virtual void RenderSDL( TextureSDL* pDestTexture);
		virtual void RenderOGL( );
		
	// protected members
	protected:
		unsigned int m_nZOrder;
		unsigned int m_nBlendFactorSrc;
		unsigned int m_nBlendFactorDest;
		
		Uint8 m_nAlpha;

		bool m_bCullingEnabled;
		bool m_bVisible;
		bool m_bPivotCentered;
		bool m_bAlphaEnabled;
		bool m_bColorKeyEnabled;
			
		float m_fAlphaRef;
		
		ColorRGB m_rColorKey;
		BLENDMODE_PRESET m_nBlendMode;
		GraphicsUVData m_rUVdata;
		//RENDER_MODE m_nRenderMode;

		Texture *m_pTexture;
	
	}; // class GraphicsObject
}; // namespace EPOC

#endif